package com.yc.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author yuancan
 *https://blog.csdn.net/ooc_zc/article/details/95231713
 */
public class TestSleep {
	
	List<Integer> before = new ArrayList<Integer>();
	List<Integer> after = new ArrayList<Integer>();
	
	public void m(int i) {
		new Thread(() -> {
			before.add(i);
			try {
//				Thread.sleep(i*60);//对照组：睡眠时间依次增长，按顺序醒来
				Thread.sleep(new Random().nextInt(2000));//实验组：随机醒来
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			after.add(i);
		}).start();
	}

	public static void main(String[] args) {
		TestSleep ts = new TestSleep();
		for (int i = 0; i < 30; i++) {
			ts.m(i+1);
		}
		
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		System.out.println("before: " + ts.before);
		System.out.println("after: " + ts.after);
	}

}
